package ex_from_web;


class Person {
    String name;
    
    public Person(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
}

//Subclass of the Person class
class Student extends Person{
    String faculty;
    
    //Student class will inherit 
    //'name' attribut and getName() method from Parent class 
    public Student(String name, String faculty) {
        super(name);
        this.faculty = faculty;
    }
  
    //new, more specific method for Student class
    public String getFaculty() {
        return faculty;
    }
}

//Subclass of the Person class
class Worker extends Person{
  String faculty;
  
  //Student class will inherit 
  //'name' attribut and getName() method from Parent class 
  public Worker(String name, String faculty) {
      super(name);
      this.faculty = faculty;
  }

  //new, more specific method for Student class
  public String getFaculty() {
      return faculty;
  }
}
public class another_example_of_inheritance {

    public static void main(String[] args) {
        Person person = new Person("Peter");
        Student student = new Student("Clara", "chemistry");
        Worker worker = new Worker("Patrick", "developpeur");
        
        System.out.println(person.getName());
        System.out.println(student.getName()); //inherited method
        System.out.println(student.getFaculty());
        System.out.println(worker.getName()); //inherited method
        System.out.println(worker.getFaculty());
    }

}